<%--
  Created by IntelliJ IDEA.
  User: guoshunw
  Date: 13-9-2
  Time: 上午10:02
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%--<%@ taglib prefix="sx" uri="/struts-dojo-tags" %>--%>
<%--<s:debug />--%>
<table border="0" class="new-request-table">

    <tr>
        <td class="label"><s:text name="request.projectOwner"/></td>
        <td>
            <s:textfield theme="simple" id="attr_projectOwner" name="attr_projectOwner"
                         value="%{req.attributes.attr_projectOwner}"/>
        </td>
    </tr>


    <tr>
        <td class="label"><s:text name="request.projectType"/></td>
        <td>
            <s:select headerKey="" headerValue="%{getText('pleaseSelect')}"
                      required="true" list="{'Program', 'Offer'}" id="attr_projectType"
                      name="attr_projectType"
                      value="%{req.attributes.attr_projectType}"
                      theme="simple"/>
        </td>
    </tr>

    <tr>
        <td class="label"><s:text name="request.componentAndRelease"/></td>
        <td>
            <s:select headerKey="" headerValue="%{getText('request.componentAndRelease.noassigned')}"
                      required="true"
                      list="componentAndReleases"
                      id="attr_componentAndRelease"
                      name="attr_componentAndRelease"
                      value="%{req.attributes.attr_componentAndRelease}"
                      theme="simple"/>

            <s:hidden name="attr_extra_componentAndRelease_name" value="None Assigned:None"
                      id="attr_extra_componentAndRelease_name" theme="simple"/>
        </td>
    </tr>

    <tr>
        <td class="label" style="width: 200px"><s:text name="request.projectStartDate"/></td>
        <td>
            <s:textfield theme="simple" cssStyle="width: 88%" id="attr_projectStartingDate"
                         name="attr_projectStartingDate"
                         value="%{req.attributes.attr_projectStartingDate}"/>(optional)
        </td>
    </tr>

    <tr>
        <td class="label"><s:text name="request.plcType"/></td>
        <td>
            <s:select headerKey="" headerValue="%{getText('pleaseSelect')}"
                      required="true" list="{'Minor', 'Major', 'Maintenance', 'Composite'}" id="attr_PLCType"
                      name="attr_PLCType"
                      value="%{req.attributes.attr_PLCType}"
                      theme="simple"/>
        </td>
    </tr>

    <tr>
        <td class="label"><s:text name="request.projectRigor"/></td>
        <td>
            <s:select headerKey="" headerValue="%{getText('pleaseSelect')}"
                      required="true" list="{'High', 'Medium', 'Low'}" id="attr_projectRigor"
                      name="attr_projectRigor"
                      value="%{req.attributes.attr_projectRigor}"
                      theme="simple"/>
        </td>
    </tr>

    <tr>
        <td class="label"><s:text name="request.projectState"/></td>
        <td>
            <s:select headerKey="" headerValue="%{getText('pleaseSelect')}"
                      required="true" list="{'COMMITTED', 'FORECAST', 'MIGRATED', 'PLANNING'}" id="attr_projectState"
                      name="attr_projectState" disabled="true"
                      value="'FORECAST'"
                      theme="simple"/>
        </td>
    </tr>

</table>

<script type="text/javascript">

    var requestForm = $('#' + global.NEW_REQUEST_TAB_ID);

    $('#attr_projectStartingDate', requestForm).datepicker({dateFormat: "yy-mm-dd"});
    $('#attr_projectType', requestForm).change(function () {
        // remove added field
        $("tr.dynamicInsert", requestForm).remove();
        if (!this.value) {
            return;
        }

        var textField = "<input id='attr_projectName' style='width:200px;' name='attr_projectName' value='${req.attributes.attr_projectName}' />_" + global.PROJECT_NAME_EXT[this.value];
        var projectNameRow = "<tr class='dynamicInsert'><td class='label'><s:text name='request.projectName'/></td><td>" + textField + "</td></tr>";
        var tr = $('tr.dynamicInsert:last()', requestForm);
        if (!tr.length) tr = $('#attr_projectState', requestForm).parents("tr");


        var hierarchy = {
            'Offer': 'Offer',
            'Program': 'PMO'
        };
        var templateName = {
            'Offer': 'Offer ',
            'Program': 'NEW_PCT_'
        }

        if ('Offer' == this.value) {
            $("#attr_componentAndRelease", requestForm).empty().append(
                    "<option value=''>None Assigned:None</option>"
            ).prop("disabled", true);
        } else if ('Program' == this.value) {
            $.post('forward-json', {resources: 'componentAndRelease'}, function (datas) {
                datas.unshift({id: '', name: 'None Assigned:None'});
                $("#attr_componentAndRelease", requestForm).empty().append(json2Options(datas, '', 'name')).prop('disabled', false);
            });
        }

        tr.after("<tr class='dynamicInsert'><td class='label'><s:text name='request.template'/></td><td>" + templateName[this.value] + 'Template' + "</td></tr>");
        tr.after("<tr class='dynamicInsert'><td class='label'><s:text name='request.hierarchy'/></td><td>" + hierarchy[this.value] + "</td></tr>");
        tr.after(projectNameRow);

    });

    $("#attr_componentAndRelease", requestForm).change(function () {
        $(this).next("input#attr_extra_componentAndRelease_name").val($("option:checked", this).text());
    });


    global.getIncludeAttributes = function () {
        var pNames = ['attr_projectOwner', 'attr_projectType', 'attr_PLCType',
            'attr_projectRigor', 'attr_projectName'];

        var pNameValidate = pNames.slice(0);

        pNames = pNames.concat([ 'attr_projectStartingDate', 'attr_projectState']);
        if ("" != $("select#attr_componentAndRelease", requestForm).val()) {
            pNames = pNames.concat(['attr_componentAndRelease', 'attr_extra_componentAndRelease_name']);
        }

        if ($('#attr_projectType', requestForm).val() != 'Offer') {
//            pNameValidate.push('attr_componentAndRelease');
        }

        var postDate = global.getAttributes(pNames, pNameValidate);
        return postDate;
    }

</script>
